package com.example.medical.controller.user;

import com.example.medical.entity.dto.*;
import com.example.medical.service.AffairsService;
import com.example.medical.utils.common.enums.Code;
import com.example.medical.utils.common.result.Result;
import com.example.medical.utils.config.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/affairs")
public class UserAffairsController {

    @Autowired
    private AffairsService affairsService;

    @PostMapping("/get_affairs_IB")
    public Result LeadershipGetAffairsIBList(@RequestBody GetAffairsListActionDto dto){
        return affairsService.UserGetAffairsGetSetList(dto);
    }

    @PostMapping("/get_affairs_OB")
    public Result LeadershipGetAffairsOBList(@RequestBody GetAffairsListActionDto dto){
        return affairsService.UserGetAffairsGetSetList(dto);
    }

    @PostMapping("/get_affairs_shift")
    public Result LeadershipGetAffairsShiftList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @PostMapping("/get_affairs_report_losses")
    public Result LeadershipGetAffairsReportLossesList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @PostMapping("/get_affairs_check")
    public Result LeadershipGetAffairsCheckList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @PostMapping("/get_affairs_repair")
    public Result LeadershipGetAffairsRepairList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @PostMapping("/get_affairs_buy")
    public Result LeadershipAffairsBuyList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @PostMapping("/get_affairs_get_set")
    public Result UserGetAffairsGetSetList(@RequestBody GetAffairsListActionDto dto){
        return affairsService.UserGetAffairsGetSetList(dto);
    }

    @PostMapping("/get_affairs_List")
    public Result UserGetAffairsList(@RequestBody GetAffairsListDto dto){
        return affairsService.UserGetAffairsList(dto);
    }

    @GetMapping("/get_affairs_detail")
    public Result UserGetAffairsDetail(@RequestParam("id")Long id){
        if (BaseContext.getCurrentId()==null) {
            return Result.errorResult(Code.NEED_LOGIN);
        }
        return Result.okResult(affairsService.getById(id));
    }

    @PostMapping("/save_affairs")
    public Result UserSaveAffairs(@RequestBody UserSaveAffairsDto dto){
        return affairsService.UserSaveAffairs(dto);
    }

    @GetMapping("/remove_affairs")
    public Result UserRemoveAffairs(@RequestParam("id") Integer id, @RequestParam("memo")String memo){
        return affairsService.UserRemoveAffairs(id,memo);
    }

    @GetMapping("/remove_affairs_arr")
    public Result RemoveAffairsArr(@RequestParam("ids")String[] ids,@RequestParam("memo")String memo){
        return affairsService.RemoveAffairsArr(ids,memo);
    }

    @GetMapping("/affairs_repair_true")
    public Result UserRepairAffairsTrue(@RequestParam("id")Integer id){
        return affairsService.UserAffairsRepairTrue(id);
    }

    @GetMapping("/affairs_repair_false")
    public Result UserAffairsRepairFalse(@RequestParam("id")Integer id,@RequestParam("memo")String memo){
        return affairsService.UserAffairsRepairFalse(id,memo);
    }
}
